|
|
|
|
|
|
|
included, the filter and sort conditions, and any join conditions to access the data from multiple tables. |
|
|
|
|
|
|
|
|
The following code is the simplest form of creating a query, in which all the records and fields are selected from a table with no other condition specified. This type of query is created by a Data control as a default. |
|
|
|
|
|
|
|
|
Dim MyDyn As Recordset
MyDynOpen Select * from Titles, adDbCon1,,,adCmdText |
|
|
|
|
|
|
|
|
This code gives you the same data you had when accessing the table directly by using the table-type recordset. The only difference is the type of recordset created. When you create a query, you can use any valid SQL statement that you need to select the correct data from the database. |
|
|
|
|
|
|
|
|
Now that you have a understanding of what it takes to create and open recordsets, you can see how to use them in an application. As you've already seen, to display data with the Data control and bound controls, you simply draw the controls on the form and then set the appropriate data field properties for the controls. The display process itself is automatic. |
|
|
|
|
|
|
|
|
With the ActiveX Data Objects, the process is only slightly more complex. You still use control objects (such as text boxes and labels) to display the data, but you assign the data to the controls manually with each record that you display. When used in this manner, the control objects are usually called unbound controls. One advantage of using unbound controls is that you can use any control to display data, not just the bound controls specifically meant to use with the Data control. |
|
|
|
|
|
|
|
|
You can access data through a recordset's Fields collection in several ways. For example, to retrieve the contents of a field named Title in a recordset called MyDyn and place it into a text box named Text1, you could do the following: |
|
|
|
 |
|
|
|
|
Use the field's ordinal position in the Fields collection as Text1.Text =MyDyn.Fields(0). |
|
|
|
 |
|
|
|
|
Use the field's name to retrieve it from the Fields collection as Text1.Text =MyDyn.Fields(Title). |
|
|
|
 |
|
|
|
|
Use the recordset collection's default to access the field as Text1.Text =MyDyn(Title). |
|
|
|
 |
|
|
|
|
Use the recordset collection's default to access the field as Text1.Text =MyDyn!Title. |
|
|
|
|
|